package com.gooddare.view.component 
{
	import com.gooddare.model.vo.GridviewItemVO;
	import com.gooddare.model.vo.GridviewVO;
	import com.riatimes.mvc.view.BaseComponent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import com.greensock.easing.Sine;
	import com.greensock.TweenMax;
	/**
	 * ...
	 * @author Lyleff
	 */
	public class TagsGroupComponent extends BaseComponent
	{
		private var vo:GridviewVO;
		private var digit:int = 0;//显示出tag的数量
		private var xPoint:int = 0;
		private var yPoint:int = 0;
		private var sum:int = 0;
		public function TagsGroupComponent(vo:GridviewVO) 
		{
			this.vo = vo;
		}
		override public function initUI () : void {
			for (var j:uint = 0; j < vo.gridlist.length; j++ ) {
				if (vo.gridlist[j].tags == 1) {
					sum++;
				}
			}
			for (var i:uint = 0; i < vo.gridlist.length; i++ ) {
				if (vo.gridlist[i].tags == 1) {
					if (digit) {
						if (digit == sum-1) {
							and();
						}else {
							comma();
						}
					}
					digit++;
					var tic:TagsItemComponent = new TagsItemComponent(i,vo.gridlist[i]);
					this.addChild(tic);
					if (xPoint+tic.width > 225) {
						xPoint = 0;
						yPoint += tic.height;
					}
					TweenMax.to(tic, 0, { y:yPoint+5,x:xPoint+1 ,alpha:0 ,blurFilter: { blurX:3, blurY:3 }} );
					TweenMax.to(tic, 0.3, {delay:i*0.05,x:xPoint,y:yPoint,alpha:1, blurFilter: { blurX:0, blurY:0 },ease:Sine.easeOut} );
					/*tic.x = xPoint;
					tic.y = yPoint;*/
					xPoint += tic.width;
				}
			}
		}
		private function and():void {
			var aTxt:TextField = new TextField();
			var tfm:TextFormat = new TextFormat();
			tfm.font = "Consolas";
			tfm.color = 0x999999;
			tfm.size = 14;
			
			aTxt.defaultTextFormat = tfm;
			aTxt.text = "and";
			aTxt.autoSize = TextFieldAutoSize.LEFT;
			aTxt.selectable = false;
			this.addChild(aTxt);
			if (xPoint+aTxt.width > 225) {
				xPoint = 0;
				yPoint += aTxt.textHeight;
			}
			aTxt.x = xPoint;
			aTxt.y = yPoint;
			xPoint += aTxt.width;
		}
		private function comma():void {
			var cTxt:TextField = new TextField();
			var tfm:TextFormat = new TextFormat();
			tfm.font = "Consolas";
			tfm.color = 0x999999;
			tfm.size = 14;
			cTxt.defaultTextFormat = tfm;
			cTxt.text = ",";
			cTxt.x = xPoint;
			cTxt.y = yPoint;
			cTxt.autoSize = TextFieldAutoSize.LEFT;
			cTxt.selectable = false;
			this.addChild(cTxt);
			xPoint += cTxt.width;
		}
		override public function initEvent(b:Boolean = true) : void {
			
		}
	}

}